capture log close
clear

log using LogFile_PreparedPublicReplicationFileStudyR1.txt, replace text

* This .do file loads the raw data for Replication of Study 1
* The raw data (identified, with IPs/etc.) is NOT included in the replication file.
* The outputted file from this code is StudyR1data_publicdatafile_cleaned.dta

* Load Study R1 demographics data
insheet using "..\PrivateDataNotInReplicationArchive\StudyR1_respondents-for-2clSigr3bCN8AvCE244x.csv", names

rename respondentid respondent_id

drop if age<18

gen d_age = age 
label var d_age "Age in years"

/*
education
1. Less than high school graduate
2. High school graduate, diploma or the equivalent (for example: GED)
3. Some college credit, no degree
4. Trade/technical/vocational training
5. Associate degree
6. Bachelor's degree
7. Master's degree
8. Professional degree
9. Doctorate degree
*/

recode education (1=1) (2=1) (3=2) (4=2) (5=2) (6=3) (7/9=4) (*=.), gen(d_educ)
label var d_educ "Education (1-4)"
label define educlab 1 "HS or less" 2 "Some college, trade, associates" 3 "BA" 4 "Post-BA"
label values d_educ educlab

/*
ethnicity
Which of the following best describes your ethnic background? If you are from multiple ethnic backgrounds, please select all the responses that apply.
[multi choice]
1. White/Caucasian
2. Black/African American
3. Asian
4. Native Hawaiian or Pacific Islander
5. American Indian or Alaskan native
98. Other race or ethnicity
99. Prefer not to answer
*/

gen d_black = (strpos(ethnicity,"2")~=0)
gen d_asian = (strpos(ethnicity,"3")~=0)
gen d_other = (strpos(ethnicity,"4")~=0) | (strpos(ethnicity,"5")~=0) | (strpos(ethnicity,"98")~=0)
label var d_black "Ethnicity=Black (1=yes)"
label var d_asian "Ethnicity=Asian (1=yes)"
label var d_other "Ethnicity=Other (1=yes)"

/*
hispanic
Are you of Hispanic, Latino or Spanish origin or descent?
[single choice]
1. Yes
2. No
*/

gen d_hispanic = hispanic==1
label var d_hispanic "Hispanic (1=yes)"

/*
gender
What is your gender?
[single choice]
1. Male
2. Female
3. Non-binary
*/

gen d_gender_female = gender==2
gen d_gender_nonbinary = gender==3
label var d_gender_female "Female (1=yes)"
label var d_gender_nonbinary "Non-binary (1=yes)"

/*
income
Which of the following ranges includes your total annual household income from all sources?
[single choice]
1. Less than $25,000
2. $25,000 to $34,999
3. $35,000 to $49,999
4. $50,000 to $74,999
5. $75,000 to $99,999
6. $100,000 to $124,999
7. $125,000 to $149,999
8. $150,000 to $174,999
9. $175,000 to $199,999
10. $200,000 to $249,999
11. $250,000 or more
99. Prefer not to say
*/

gen d_income=income
replace d_income=12 if d_income==99
gen d_income_rf= d_income==12
label var d_income "Income (1-11, 12=refused)"
label var d_income_rf "Income refused (1=yes)"

label define inclabel 1 "<$25,000" 2 "$25,000 to $34,999" 3 "$35,000 to $49,999" 4 "$50,000 to $74,999" 5 "$75,000 to $99,999" 6 "$100,000 to $124,999" 7 "$125,000 to $149,999" 8 "$150,000 to $174,999" 9 "$175,000 to $199,999" 10 "$200,000 to $249,999" 11 "$250,000 or more" 12 "Prefer not to say"
label values d_income inclabel

/*
political_ideology
In general, do you think of yourself as...
[single choice]
1. Extremely liberal
2. Liberal
3. Slightly liberal
4. Moderate, middle of the road
5. Slightly conservative
6. Conservative
7. Extremely conservative
*/

gen d_ideo7 = political_ideology
label var d_ideo7 "Ideology (1=Extremely Lib.; 7=Extremely Consv.)"

/*
political_party_preference
Generally speaking, do you think of yourself as a...
[single choice]
1. Strong Democrat
2. Democrat
3. Independent, close to Democrat
4. Independent
5. Independent, close to Republican
6. Republican
7. Strong Republican
98. Other
99. No preference
*/

gen d_pid7 = political_party_preference
replace d_pid7=4 if d_pid7==98 | d_pid7==99
label var d_pid7 "Partisanship (1=Strong Dem.; 7=Strong Rep)"

keep respondent_id d_*

order respondent_id d_age d_gender_female d_gender_nonbinary d_educ d_income d_income_rf d_black d_asian d_other d_hispanic d_pid7 d_ideo7

compress

save ..\PrivateDataNotInReplicationArchive\StudyR1_demographics.dta, replace
clear

insheet using "..\PrivateDataNotInReplicationArchive\StudyR1_Police+Interaction+Vignettes+Replication+May+2024_May+31,+2024_16.20.csv", names

drop if responseid ==""
drop if respondent_id =="" | respondent_id =="ricktest444"
keep if status=="IP Address"
keep if intro_prompt=="I agree to participate"
keep if huber_acq_identify=="Because he left his ID"

gen got_hard_acq= huber_acq_steal=="About $1,500"
label var got_hard_acq "Correct harder pre-treatment attention check (1=yes)"

drop responseid -userlanguage 
drop meta*
drop rid-updated 
drop status ipaddress

joinby respondent_id using "..\PrivateDataNotInReplicationArchive\StudyR1_demographics.dta", unmatched(both)
tab _merge

keep if _merge==3
drop _merge

gen study="StudyR1"

* Preferred Punishment Vignette
tab vig_should_1
gen SR1_out_preferredpunish=.
replace SR1_out_preferredpunish=0 if vig_should_1==`"Left after learning the gunshot call was a false alarm, and not approached Parsons"'
replace SR1_out_preferredpunish=1 if vig_should_1==`"Left the park after speaking with Parsons"'
replace SR1_out_preferredpunish=2 if vig_should_1==`"Escorted Parsons from the park and left"'
replace SR1_out_preferredpunish=3 if vig_should_1==`"Escorted Parsons from the park and issued him a verbal warning for disorderly conduct"'
replace SR1_out_preferredpunish=4 if vig_should_1==`"Escorted Parsons from the park and issued him a ticket for disorderly conduct"'
replace SR1_out_preferredpunish=5 if vig_should_1==`"Escorted Parsons from the park and arrested him for disorderly conduct"'
label var SR1_out_preferredpunish "Preferred Punishment (0-5)"
label define vpplab 0 "Just left" 1 "Speak and leave" 2 "Just Escorted" 3 "Escorted and warn" 4 "Escorted and ticket" 5 "Arrest"
label values SR1_out_preferredpunish vpplab

* Fairness to Civilian
tab vig_fair_1
gen SR1_out_fairciv = .
replace SR1_out_fairciv=0 if vig_fair_1==`"Unfairly"'
replace SR1_out_fairciv=1 if vig_fair_1==`"Somewhat unfairly"' 
replace SR1_out_fairciv=2 if vig_fair_1==`"Neither unfairly nor fairly"'
replace SR1_out_fairciv=3 if vig_fair_1==`"Somewhat fairly"' 
replace SR1_out_fairciv=4 if vig_fair_1==`"Fairly"' 
label var SR1_out_fairciv "Fairness of treatment of civilian (0-4)"
label define fairlab 0 "Unfairly" 1 "Somewhat unfairly" 2 "Neither unfairly nor fairly" 3 "Somewhat fairly" 4 "Fairly"
label values SR1_out_fairciv fairlab

* Fairness to Officer
tab vig_fair_2
gen SR1_out_faircop = .
replace SR1_out_faircop=0 if vig_fair_2==`"Unfairly"'
replace SR1_out_faircop=1 if vig_fair_2==`"Somewhat unfairly"' 
replace SR1_out_faircop=2 if vig_fair_2==`"Neither unfairly nor fairly"'
replace SR1_out_faircop=3 if vig_fair_2==`"Somewhat fairly"' 
replace SR1_out_faircop=4 if vig_fair_2==`"Fairly"' 
label var SR1_out_faircop "Fairness of treatment of officer (0-4)"
label values SR1_out_faircop fairlab

* Fairness of punishment
tab vig_fair_punish_1
gen SR1_out_fairpun = . 
replace SR1_out_fairpun=0 if vig_fair_punish_1==`"Unfair"'
replace SR1_out_fairpun=1 if vig_fair_punish_1==`"Somewhat unfair"' 
replace SR1_out_fairpun=2 if vig_fair_punish_1==`"Neither unfair nor fair"'
replace SR1_out_fairpun=3 if vig_fair_punish_1==`"Somewhat fair"' 
replace SR1_out_fairpun=4 if vig_fair_punish_1==`"Fair"' 
label var SR1_out_fairpun "Fairness of punishment (0-4)"
label values SR1_out_fairpun fairlab

* Treatments
gen T_civilianwhite = z_citizen_race=="White"
label var T_civilianwhite "Civilian White (1=yes)"

gen T_officerwhite = z_cop_race=="White"
label var T_officerwhite "Office White (1=yes)"

label define bwlabcit 0 "Civilian Black" 1 "Civilian White" 
label values T_civilianwhite bwlabcit
label define bwlaboff 0 "Officer Black" 1 "Officer White" 
label values T_officerwhite bwlaboff

gen T_x_bothwhite= (T_civilianwhite==1) * (T_officerwhite==1)
label var T_x_bothwhite "Both Civilian and Officer White"

gen T_x_offwhitecivblack = (T_civilianwhite==0) * (T_officerwhite==1)
label var T_x_offwhitecivblack "Civilian Black and Officer White"

gen T_x_offwblackcivwhite =  (T_civilianwhite==1) * (T_officerwhite==0)
label var T_x_offwblackcivwhite "Civilian White and Officer Black"

gen T_officerdecision = .
replace T_officerdecision=0 if z_outcome=="escort"
replace T_officerdecision=1 if z_outcome=="ticket"
label var T_officerdecision "Office gave ticket (1=yes, 0=no)"
label define ofdlab 0 "Escort" 1 "Ticket"
label values  T_officerdecision ofdlab

gen T_demeanor =.
replace T_demeanor=0 if z_interaction==`"AP:AP"'
replace T_demeanor=1 if z_interaction==`"AP:AH"' 
replace T_demeanor=2 if z_interaction==`"AH:AH"'
replace T_demeanor=3 if z_interaction==`"AH:AP"'
label var T_demeanor "Demeanor conditions"
label define demeanorlab 0 "Both polite" 1 "Hostile Civilian, Polite Officer" 2 "Both Hostile (Officer First)" 3 "Polite Civilian, Hostile Officer"
label values T_demeanor demeanorlab
tab T_demeanor, gen(T_i_demeanor)
drop T_i_demeanor1
label var T_i_demeanor2 "Hostile Civilian, Polite Officer"
label var T_i_demeanor3 "Both Hostile (Officer First)"
label var T_i_demeanor4 "Polite Civilian, Hostile Officer"

drop intro_prompt- huber_acq2_t_clickcount  probability_zero_1-murderpunish q127 respondent_id *click* *submit* vig_should_1 vig_fair_* z_citizen_race z_cop_race z_outcome z_interaction cop_text_1 civ_text_1 cop_text_2 civ_text_2 outcome_text_1 outcome_text_2 

compress
save StudyR1data_publicdatafile_cleaned.dta, replace

log close
